package com.yaoli.niuke;

import com.yaoli.ajob.TreeNode;

/**
 * Created by will on 2017/5/9.
 */
public class _011_Test {

    public static void main(String[] args) {
        _011_Test test = new _011_Test();
        TreeNode  a = new TreeNode(10);
        TreeNode  b = new TreeNode(5);
        TreeNode  c = new TreeNode(12);

        TreeNode  d = new TreeNode(4);
        TreeNode  e = new TreeNode(7);




        a.setLeft(b);
        a.setRight(c);

        b.setLeft(d);
        b.setRight(e);
        test.Convert(a);
    }


    TreeNode pre = null;
    public TreeNode Convert(TreeNode pRootOfTree) {

        if(pRootOfTree == null){
            return pRootOfTree;
        }
        Convert(pRootOfTree.right);

        if(pre == null){
            pre = pRootOfTree;
        }else{
            pre.left = pRootOfTree;
            pRootOfTree.right = pre;
            pre = pRootOfTree;
        }

        Convert(pRootOfTree.left);

        return pre;
    }
}
